<!--
 * @Description: websocket
 * @Author: your name
 * @Date: 2023-10-07
 * @LastEditTime: 2023-10-07
 * @LastEditors: Please set LastEditors
-->
<template>
  <div class="page">
    <el-button @click="createWb" type="primary">websocket-vue组件</el-button>
    <el-button @click="jsWb" type="primary">websocket-js工具类</el-button>
    <WebSocket
      ref="webSocket"
      title="websocket"
      v-bind="obj"
      :successCallback="successCallback"
    />
  </div>
</template>
<script>
import WebSocket from '@/components/Websocket'
import WebsocketClass from '@/utils/webSocket'

export default {
  name: 'Websocket',
  components: { WebSocket },
  data() {
    return {
      obj: {
        url: '/ami/ma01-02-081/transSystemSearchSocket',
        sendData: {
          agentId: 'sqlQuery',
          data: {
            exeSql: '',
            orgNo: '',
            taskDesc: '',
            taskId: '',
            taskName: '',
            taskType: ''
          }
        }
      },
      wb: null
    }
  },
  beforeDestroy() {
    this.wb && this.wb.closeWebSocket()
  },
  methods: {
    createWb() {
      this.$refs.webSocket.createWebSocket()
    },
    jsWb() {
      this.wb = new WebsocketClass(
        'websocket',
        '/ami/ma01-02-081/transSystemSearchSocket',
        this.obj.sendData.data,
        res => {
          console.log(res)
        }
      )
      this.wb.createWebSocket()
    },
    successCallback(data) {
      console.log(data)
    }
  }
}
</script>
<style lang="scss" scoped></style>
